package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.CommodityDetailsBiz;
import cn.hrlly.tao2shou.biz.CommodityDetailsBizImpl;
import cn.hrlly.tao2shou.domain.Commodity;
import cn.hrlly.tao2shou.listener.OnCommodityDetailsListener;
import cn.hrlly.tao2shou.view.view_interface.CommodityDetailsView;

/**
 * User: gengliang
 * Date: 2016-01-28
 * Time: 19:28
 */

public class CommodityDetailsPresenterImpl implements OnCommodityDetailsListener,CommodityDetailsPresenter {

    private CommodityDetailsBiz commodityDetailsBiz;
    private CommodityDetailsView commodityDetailsView;

    public CommodityDetailsPresenterImpl(CommodityDetailsView commodityDetailsView,Context context){
        this.commodityDetailsBiz=new CommodityDetailsBizImpl(this,context);
        this.commodityDetailsView=commodityDetailsView;
    }

    @Override
    public void showCommodityDetails() {
        Commodity commodity=new Commodity();
        commodity.setReleaseId(commodityDetailsView.getReleaseId());
        commodityDetailsBiz.showCommodityDetails(commodity);
    }

    @Override
    public void closeDataBase() {
        commodityDetailsBiz.closeDataBase();
    }

    @Override
    public void showCommodityDetailsSucc(Commodity commodity) {
        commodityDetailsView.showCommodityDetails(commodity);

        //将查看历史纪录插入数据库
        commodityDetailsBiz.saveHistory(commodity,commodityDetailsView.getReleaseId());
    }

    @Override
    public void showCommodityDetailsFail(String errorMessage) {
        commodityDetailsView.showMessage(errorMessage);
    }

    @Override
    public void showCommodityDetailsFail(int errorMessage) {
        commodityDetailsView.showMessage(errorMessage);
    }
}
